<!--
标签页 注意切换时 考虑重新渲染统计图 不然为空
-->
<template>
  <el-collapse v-model="elCollapseValue" class="mc-el-collapse" v-bind="$attrs" v-on="$listeners"  @change="change">
    <slot></slot>
  </el-collapse>
</template>

<script>
import McCommon from "./McCommon";
export default {
  name: 'mc-el-collapse',
  data () {
    return {

    }
  },
  computed:{
    elCollapseValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    }
  },
  props:{
    value:{type:[String,Array],default:null}
  },
  mounted () {
    if(window.iframeUi){
      var cacheValue = this.getCache();
      if(cacheValue){//第一次是没值就别改动
        this.$emit("input",cacheValue);//只要在布局里就给它加载 就弹出来
      }
    }
  },
  updated:function(){
    if(window.iframeUi){
      this.$nextTick(function(){//虚拟dom转化为真实dom后触发 这样动态新增的结构里 仍然可以被拖拽
        window.iframeUi.magicalApi.addApiTask({methodName:"refreshDragEvent"});
      })
    }
  },
  methods:{
    setCache(val){
      if(!window.__mcCollapse){
        window.__mcCollapse={};
      }
      var mcId = McCommon.util.findMcId(this.$el,'id');
      if(mcId){
        window.__mcCollapse[mcId] = val;
      }
    },
    getCache(){
      if(!window.__mcCollapse){
        window.__mcCollapse={};
      }
      var mcId = McCommon.util.findMcId(this.$el,'id');
      if(mcId){
        return window.__mcCollapse[mcId];
      }
      return null;
    },
    change(activeNames){
      console.log("click")
      if(window.iframeUi){
        this.setCache(activeNames);
        this.$emit("input",activeNames);
        setTimeout(function(){new IframeComponents().execute();},300)
      }
      this.$emit("change",activeNames);
    }
  }
}
</script>

<style lang="scss">

</style>
